package com.example.demo.serialize;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

/**
 * 反序列化
 */
//@JsonComponent
public class DeserializerJson extends JsonDeserializer<Object> {

    @Override
    public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        System.out.println("反序列化deserialize......");
        String treeNode = jsonParser.getCodec().readTree(jsonParser).toString();
        System.out.println("treeNode:" + treeNode);
        System.out.println("text:" + jsonParser.getText());
        System.out.println("object:" + jsonParser.getCurrentValue().toString());
        Object obj = JSON.toJSON(treeNode);
        return obj;
    }
}
